#include<reg52.h>
#include"digit.h"
#include"delay.h"

unsigned char code digits[]={ 
                0x3F,  //"0"
                0x06,  //"1"
                0x5B,  //"2"
                0x4F,  //"3"
                0x66,  //"4"
                0x6D,  //"5"
                0x7D,  //"6"
                0x07,  //"7"
                0x7F,  //"8"			      
                0x6F,  //"9"
};				 

char display_digit(unsigned char wela,unsigned char dula)
{
  if(wela<0||wela>7||dula<0||dula>9)
  return -1;
  WELA=1;
  P0=0xFF;
  P0&=~(1<<(7-wela));
  WELA=0;

  DULA=1;   
  P0=digits[dula];
  DULA=0;
  return 0;
}

char display_num(unsigned int num)
{
  	unsigned int div = 0;
	unsigned char rema = 0;
	unsigned char index = 0;
		
	if(num < 0 || num > 65535)
		return -1;
	while((div = num / 10) > 0)
	{
		rema = num % 10;
		display_digit(index,rema);
		num = div;
		index++;
		delay_ms(2);
	}
	rema = num % 10;
	display_digit(index,rema);
	return 0;
}